﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Data;
using System.Data.SqlClient;
//using System.Configuration;
using System.Web.Configuration;

// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Procedure" in code, svc and config file together.
public class QOTStorageWCFService : IQOTStorageWCFService
{
	public void DoWork()
	{
    }

    public void AddProcedure(string XML)
    {
        Nizm0.QOT.Library.Objects.ProcedureInfo proc = Nizm0.QOT.Library.Objects.ProcedureInfo.Deserialize<Nizm0.QOT.Library.Objects.ProcedureInfo>(XML); ;
        //proc = proc.Deserialize<Nizm0.QOT.Library.Objects.ProcedureInfo>(procedure);
        using (SqlConnection sqlcon = new SqlConnection())
        {
            sqlcon.ConnectionString = WebConfigurationManager.ConnectionStrings["WCFContext"].ToString();
            sqlcon.Open();
            SqlTransaction tran = sqlcon.BeginTransaction();
            try
            {
                //sqlcon.ConnectionString = WebConfigurationManager.ConnectionStrings["WCFContext"].ToString();
                SqlCommand command = new SqlCommand();
                command.Connection = sqlcon;
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "AddProcedure";
                command.Parameters.Add(new SqlParameter("Name", proc.Name));
                command.Transaction = tran;
                command.ExecuteNonQuery();
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
            }
            finally
            {
                sqlcon.Close();
            }

        }
    }

    public void AddProcedure(Nizm0.QOT.Library.Objects.IProcedure procedure)
    {
    }

    public string FindProcedureByName(string name)
    {
        return string.Format("You entered: {0}", name);
    }

    public List<string> GetAllProcedures()
    {
        List<string> list = new List<string>();
        return list;
    }
}
